Play! How to retrieve field value in a template tag having entity and the field name passed separately as parameters?

I am not aware of an easy answer, but it is possible. You can create a fast tag, and use reflection to get the field you are after. You can get more info on Fast Tags here Can someone explain how to use FastTags However, wouldnt it be easier to just send the specific field through to your tag?

I am not aware of an easy answer, but it is possible. You can create a fast tag, and use reflection to get the field you are after. You can get more info on Fast Tags here - Can someone explain how to use FastTags However, wouldnt it be easier to just send the specific field through to your tag?

I have to use both: the field name and the field value so I wanted to compress the parameters list. If there is no easy way to do it I'll use the extended parameters list. – Rajish Apr 29 at 10:45.

The parameters are stored in a variable called renderArgs. I'm not sure if this is directly accessible inside templates, but if this doesn't work: renderArgs. Get(_entity) then you can probably access it indirectly using the static method: Scope.RenderArgs.current().

Get(_entity) Accessing a named field of that entity is then a matter of reflection. However, I agree with the suggestion that there has to be an easier way. If you find yourself doing reflection like that, it usually (not always) means you've over-engineered something.

You could just pass those parameters to a utility class that uses reflection to find the String value you actually want displayed. ${play.sample.util.ReflectUtil. Get(_entity, _field)} play.sample.util.

ReflectUtil: public static String get(String entity, String field) { String displayValue = ... // look up value ... return displayValue; } Or a FastTag would work too.

When I needed to do this I did something similar to the CRUD module. I call the tag as #{sometag 'entity. Field' /} then in the fast tag I have (roughly): String parts = args.

Get("arg"). Split("\\. "); Object entity = play.mvc.Scope.RenderArgs.current().

Get(parts0); String field = String. ValueOf(parts1); Object value = groovy.util.Eval. Me("_caller", template.

Template, "_caller. " + args. Get("arg").

Replace(". ", "?. ")).

For me it works with easy way. I have pager tag: #{pager model:productList, totalCount:total /} And in pager. Tag I have: ${_totalCount} #{list items:_model.

GetStartPage(params. PageNumber).._model. GetPageCount(params.

PageNumber), as:'i'} %{selectedClass=i.toString()==(params. PageNumber==null? "1" : params.

PageNumber)? "selected":""%} #{if selectedClass == "selected"} ${i} #{/if} #{else} ${i} #{/else} #{/list}.

I'm sorry but having read your code several times I still don't get where is the part answering my question. – Rajish Apr 29 at 11:03 Your question is: how to pass entity and field name to template tag, right? I just showed you a working example how to achieve this.

Maybe I just missed something. – Tim Apr 29 at 12:26 As far as I see you pass some entity and a number. There is no place in your code where you get the field value using its name (not the value passed as a parameter).

Look closely at the examples given in the question. – Rajish Apr 29 at 12:54 _model. GetStartPage in the code.

You can call field the same way the method. Maybe I just misunderstood your question. Sorry – Tim Apr 29 at 19:21.

Object entity = play.mvc.Scope.RenderArgs.current(). String field = String. Object value = groovy.util.Eval.me("_caller", template.

Template, "_caller." + args.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions