0

Consider the following 'toy example':

I have a 'Student' class:

public class Student {
    private String name;            
    // getters and setters
}

A managed bean, called 'StudentBean':

@ManagedBean(name = "stdBean")
@ViewScoped
public class StudentBean {
    private List<Student> lstStudents = new ArrayList<>();
    public List<Student> getLstStudents() {
        // populate the lstStudents with some students.        
    }
    public void remove(Student std) {
        lstStudents.remove(std);
    }
}

And a XHTML file with the following content within the body tag:

<h:form>
   <h:dataTable value="#{stdBean.lstStudents}" var="std">
                <h:column>
                    <f:facet name="header">Name</f:facet>
                        #{std.name}
                </h:column>
                <h:column>
                    <h:commandLink action="#{stdBean.remove(std)}" value="Remove"/>
                </h:column>
   </h:dataTable>
</h:form>

Observe that I'm passing 'std' (that is an instance of 'Student' that belongs to 'lstStudent' list) as a parameter for the 'remove' method.

The question is: for which reasons I do not need a converter for the Student class?

Best regards. Paulo.

  • It is not visible what `obj` is but it will have already been passed through the corresponding JSF converter before the associated managed bean gets a chance to operate upon that object. Thus, it has already been converted to a desired type by that converter. – Tiny Feb 01 '16 at 14:05
  • @Tiny: nope, EL method arguments are not passed forth and back via HTML/HTTP. They're just evaluated server side in current EL context. – BalusC Feb 01 '16 at 15:06
  • I did not assume `managedBean.myMetohd(obj);` might have been written in EL terminated with a semicolon :) "*When I'm calling a method from a managed bean, I can do something like this (without a converter)*". – Tiny Feb 01 '16 at 15:13
  • @Tiny: I see. Well, the question did outside EL context otherwise not make any sense :) – BalusC Feb 01 '16 at 17:45
  • @Tiny: the question was really bad-formulated. I updated it... – Paulo Júnior Feb 02 '16 at 18:39
  • @BalusC: the question was really bad-formulated. I updated it... – Paulo Júnior Feb 02 '16 at 18:40
  • I understand you're after all asking for the opposite, but as the duplicate says, a converter is necessary when data is transferred via HTML output and HTTP request parameter. An EL method argument is exactly the opposite, it isn't passed forth and back via HTML/HTTP at all. – BalusC Feb 02 '16 at 18:42
  • Thanks @BalusC. I'll read the duplicate question. – Paulo Júnior Feb 03 '16 at 11:13
  • @BaluC: I read the duplicate question and I opened the source code generated by JSF from the code of my question. I observed that JSF generates a JavaScript method call from the "h:commandLink" tag, called "mojarra.jsfcljs(...)". This method receives an HTML element as parameter. May you explain me more about this method. Thanks. – Paulo Júnior Feb 11 '16 at 10:07

0 Answers0