Pregunta

ArticleDto.java

public class ArticleDto {   
    ...
    private CategoryDto categoryDto;
    ...
}

CategoryDto.java

public class CategoryDto {  
    ...
    private Long id;
    ...
}

global_en.properties

...
categoryDto.id=ID
...

...
articleDto.categoryDto.id=Category
...

new_article.jsp

<s:form action="addArticle">
    <s:select key="articleDto.categoryDto.id" />
    <s:textfield key="articleDto.title" />
    <s:submit />
</s:form>

In the resulting HTML I get the wrong label for "articleDto.categoryDto.id". I get "ID" instead of the desired "Category".

I seems like of the key "articleDto.categoryDto.id" it first match the subString "categoryDto.id".

If I remove the "categoryDto.id=ID" entry from the .properties file, it get the corrent value "Category".

Shouldn't be "articleDto.categoryDto.id" higher priority instead of "categoryDto.id"?

¿Fue útil?

Solución

I solved this adding "bundle" at the beginning of all the entries in global_en.properties:

...
bundle.categoryDto.id=ID
...

...
bundle.articleDto.categoryDto.id=Category
...

and than in the form:

    <s:select name="bundle.articleDto.categoryDto.id" />

Solved, but still dont know why struts2 wasn't able to recognize the previous solution. The problem is in getText(). It searches in the value stack that contains also action variable. And in the action I have an ArticleDto, with getter and setter. If I remove the getter, all goes fine. This getter seems to go in some strange conflict.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top