Search code examples
jspservletsjstlelscriptlet

Converting this scriptlet code to JSTL / EL?


I don't know how to recode this scriptlet code to JSTL / EL taglib. The statements are quite simple but it uses session data and make new objects which I don't know how to do in JSTL / EL. Is it possible to recode this to JSTL / EL or do I need to put it in a preprocess servlet? If I need the preprocess servlet then I still don't know how to manage since there is no specific request handler for this view, only an access to the web page that populates a session object to our jsp page. How can I rewrite this to JSTL / EL?

<%
    final Logger logger = Logger.getLogger("arendeprocess_grunduppgifter_visa.jsp");
    ArendeProcessPageController apc = new ArendeProcessPageController(request);
    GrunduppgifterPageController pc = new GrunduppgifterPageController(request);
    String arendeTyp = apc.getArendeTyp();
    boolean showSearch = false;
    int vectr = 0; // får bara användas i errormessages.jspf
    IFormData ifData = PandoraManager.getSessionData(session).getFormData();

    AnsokanInfo ansokanInfo = apc.getAnsokanInfo();
    PersonInfo editPerson = new PersonInfo();
    if(ansokanInfo != null && ansokanInfo.hasEditPersonInfo()) {
        editPerson = ansokanInfo.getEditPersonInfo();
    } else {
        editPerson.setFornamn(apc.getNyregPerson().getFornamn());
        editPerson.setEfternamn(apc.getNyregPerson().getEfternamn());
        editPerson.setForetag(apc.getNyregPerson().getForetag());
        //editPerson.setOrgnr(apc.getNyregPerson().getOrgnr());
        editPerson.setLandKod(apc.getNyregPerson().getLandKod());
    }
    if(apc.getLatestAction().equals("Namnsokning") && apc.getLatestActionCommand().equals("search")) {
        showSearch = true;    
    }
    List<PersonInfo> sokandeList = ansokanInfo.getSokandeList();
    List<PersonInfo> uppfinnareList = ansokanInfo.getUppfinnareList();
    List<PersonInfo> ombudList = ansokanInfo.getOmbudList();
    List<Prioritet> prioriteter = ansokanInfo.getPrioriteter();
    List<Deposition> depositioner = ansokanInfo.getDepositioner();
    request.setAttribute("request", request);
    request.setAttribute("ansokanInfo", ansokanInfo); 
    request.setAttribute("editPerson", editPerson);
    request.setAttribute("apc", apc);
    request.setAttribute("sokandeList", sokandeList);
    request.setAttribute("uppfinnareList", uppfinnareList);
    request.setAttribute("ombudList", ombudList);
    request.setAttribute("GrunduppgifterConstants", new GrunduppgifterConstants());
%>

Solution

  • Yes anything you can write in scriptlets can be written in EL/Custom Tags.

    There are two ways :

    • Change all Controller classes as Use Beans and write the above code using EL.
    • Move the above code to Custom Tags and eliminate scriptlets