2010-06-11 2 views
1

풍부한 제안을 구축하려고하는데 입력 값이 null 인 이유를 이해하지 못합니다. 무언가를 입력 할 때 inputText 값이 사용되지 않는 이유는 무엇입니까?제안 사항 - 왜 입력이 null입니까? (솔기 프레임 워크)

.xhtml 코드 :

<h:inputText value="#{suggestion.input}" id="text"> 
</h:inputText> 
<rich:suggestionbox id="suggestionBoxId" for="text" tokens=",[]" 
        suggestionAction="#{suggestion.getSimilarSpacePaths()}" var="result" 
        fetchValue="#{result.path}" 
        first="0" 
        minChars="2" 
        nothingLabel="No similar space paths found" 
        columnClasses="center" 
     > 
    <h:column> 
     <h:outputText value="#{result.path}" style="font-style:italic"/> 
    </h:column> 
</rich:suggestionbox> 

액션 클래스

:

@Name("suggestion") 
@Scope(ScopeType.CONVERSATION) 
public class Suggestion { 
@In 
protected EntityManager entityManager; 

private String input; 

public String getInput() { 
    return input; 
} 

public void setInput(final String input) { 
    this.input = input; 
} 

public List<Space> getSimilarSpacePaths() { 
    List<Space> suggestionsList = new ArrayList<Space>(); 
    if (!StringUtils.isEmpty(input) && !input.equals("/")) { 
     final Query query = entityManager.createNamedQuery("SpaceByPathLike"); 
     query.setParameter("path", input + '%'); 
     suggestionsList = (List<Space>) query.getResultList(); 
    } 
    return suggestionsList; 
} 

} 그래서

, 입력이 널 (null) beeing는, suggestionList 항상 ... 입력의 값이 비어 왜 게시되지 않았습니까?

답변

2

음, 핵심은 풍부한 제안을위한 매개 변수가있는 메소드를 사용하는 것입니다!

@Name("suggestion") 
public class Suggestion { 


@In 
protected EntityManager entityManager; 

public List<String> getSimilarSpacePaths(final Object input) { 
    //prepare the list with the strings 
     //... 
    return suggestionsList; 
    } 
    } 

과 .xhtml :

<h:inputText id="text" size="80" value="#{accountHome.instance.creationPath}"> 
</h:inputText> 
<rich:suggestionbox id="suggestionBoxId" for="text" tokens=",[]" 
    suggestionAction="#{suggestion.getSimilarSpacePaths}" var="result" 
    fetchValue="#{result}" 
    first="0" 
    minChars="2" 
    nothingLabel="No similar space paths found" 
    columnClasses="center" 
    width="350" 
    > 
<h:column> 
    <h:outputText value="#{result}" style="font-style:italic"/> 
</h:column> 
<a:support ajaxSingle="true" event="onselect"> 
    <f:setPropertyActionListener value="#{result}" target="#{accountHome.instance.creationPath}"/> 
</a:support> 
</rich:suggestionbox> 

어쩌면에 대한 유용한 될 것 매개 변수는 그래서, 대신 위의 클래스의 그것이 있어야 무슨 InputText]를의 사용자 유형 .... 실제로 다른 사람 :

0

이것이 유효한 지 확실하지 않지만 Java는 getters와 setter를 사용하여 JSP로 필드를 캡슐화합니다. xhtml 파일에서 자바를 사용하려고하기 때문에, 당신이하는 일이라고 추측합니다.

안녕하세요. #{suggestion.input}입니다. JSP에서는 사용자가 만든 getter 인 suggestion.getInput()이됩니다.

많은 경우와 마찬가지로 suggestion.SimilarSpacePaths이라고합니다.

JSP는 값을 올바르게 평가할 수없는 경우 null 또는 빈 문자열 (어떤 것이 확실하지 않음)을 기본값으로 사용합니다. JSP에 대한 디버깅 플러그인이 있으므로 웹 페이지를 컴파일하고 확인하지 않고도이를 알 수 있습니다.

도움이 되었습니까?

+0

불행히도, 아닙니다. 메소드 이름은 디버그 모드에서 메소드가 성공적으로 "catched"되었으므로 괜찮습니다. –

관련 문제