Custom HTML parameters for component - java

When you use standard t:pagelink component you can pass arbitrary number of custom HTML attributes like class or some data attributes:
<t:pagelink page="somepage" data-somedata="test">link name</t:pagelink>
And they will be included in generated a tag:
link name
This does not work for components created by me. When I have:
<t:misc.custompagelink page="somepage" data-somedata="test">link name</t:misc.custompagelink>
The generated HTML looks like this:
link name
How to mimick the behaviour of standard t:pagelink component?

There are 2 ways to do this, both easy:
1) Read and follow the "Informal Parameters" section at http://tapestry.apache.org/component-parameters.html
2) Have your component class extend Tapestry's "Any" component (http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/Any.html)

Related

spullara mustache java partials

I'm having trouble finding examples of how to implement partials using the Spullara Mustache java implementation. Their github page doesn't seem to have any straight forward partial examples.
In DefaultMustacheFactory I see methods for compilePartial and resolvePartialPath, but I'm not sure if I am supposed to override them or what.
I currently have this, and it works great without partials. TemplateContent contains the raw template html including mustache syntax.
public Mustache compileMustacheTemplate(String templateCode, String templateContent){
return new DefaultMustacheFactory().compile(new StringReader(templateContent),templateCode);
}
Pretty straight forward. But what if template content had {{>partialName}} inside it? I think I need to somehow specify that template content as well.
Do I need to extend DefaultMustacheFactory or possibly another class to specify the name of my partial and the content for it?
I believe I'm just missing something.
Thanks,
Matt
Assuming your template files are stored in a folder 'src/main/resources/org/example/web/' and you have one template "page.html" file referencing two other template files 'header.html' and 'footer.html'. Your template file "page.html" should look like this:
{{> src/main/resources/org/example/web/header.html}}
... some content ...
{{> src/main/resources/org/example/web/footer.html}}

ZK Custom Validation Style

Is there a way to style the validation message (WrongValueException etc.)
Because it is absolutly not touch friendly.
I searched in the docs of zk but i found nothing.
Currently I use Zk 6.5.2
The validation messages are displayed in an ErrorBox widget.
The z class is z-errbox. Unfortunately, I don't believe ZK gives you a hook to specify a custom z class for any particular ErrorBox. This means the only way to override the style for an ErrorBox is to override the style for all ErrorBoxes. It sounds like that might work for you, if so, you can see the the ZK style class definitions in the source code.
For example, you could override the validation text color with..
.z-errbox-center {
color: blue;
}
As a side note, you'll probably want to hook your custom CSS file into ZK rather than manually loading it on the page. This will ensure it gets loaded as fast as possible and the user won't see the styles change as the page loads.
(in WEB-INF/zk.xml)
<desktop-config>
<theme-uri>/css/style.min.css</theme-uri>
</desktop-config>
You can read more about the theme-uri tag in the documentation.

Mapping textid's to text

I have application written in spring, it communicate with another application, I received objects and now I have to map text id's to text in specific (given in object) language.
File with text id's and text looks like:
message.id=message
There is one file per language.
I'm looking for solution.
Spring provides some built-in support for internationalization in the form of MessageSources. See 3.13.1 Internationalization using MessageSource.
That's a job for the Java ResouceBundle class.
Basic usage:
ResourceBundle bundle = ResourceBundle.getBundle("path.on.the.classpath", requiredLocale);
String text = bundle.getString(textId);
You should handle MissingResourceExceptions etc. and maybe you even want to cache the bundles like some libraries/webframeworks do.

In Xwork, Can't -validation.xml be placed somewhere else than in the same package as the corresponding Action class

I'm working on service side POJO validation using xwork.
I am having an action, say ValidationAction.java, and I have a corresponding xml file named
ValidationAction-validation.xml, which has validation rules on fields.
As per the specification and the documentation I could find, I understand that this xml file should be kept in the same package as the ValidationAction.java file.
However, since I do have many java files to go through validation, and hence many corresponding xml files, I don't want to put them together in the same package.
I want to have a different folder/package for the xml files.
Is there any way out for this?
Thanks and regards.
You are putting them in the same pacage because that's how xwork validators work. What you can do, if you don't want to do all this, is implement the Validatable interface: define a custom validate() method on your action which will be called before the Action will be executed.
Example:
public void validate() {
if (todoManager.getTodo(id) == null) {
String error = getText("todo.err.notFound");
addActionError(error);
}
}

How to add custom VariableResolver to JSP Context in Jsp 2.0 to support special EL?

I'm building my own JSP Tag Library which need to support some features that Application developers can use like this:
<w:user-label id="usrlb" value="${session.user}"/>
<w:textbox id="tb" label="User Name" value="${usrlb.value.name}"/>
which means I want my EL can interact with my Tag declaration. and also I need to add stack concept into this library to support "id namespace" or something.
My current research leads me to wrap default JspFactory like this:
JspFactory.setDefaultFactory(new JspFactoryImpl(JspFactory.getDefaultFactory()));
Which could work in Tomcat5.5 although it's not a good idea.
Is there any other more pretty way to do that?
You could have your <w:user-label /> tag class simply add a variable to one of the context' scopes (request, session, ...) so EL expressions can find it? If the bean you add to the scope follows JavaBeans conventions, nested properties should be available using EL.
You can just define your tag attributes with <rtexprvalue>false</rtexprvalue>, then you will receive expressions as Strings which you can parse manually.

Categories

Resources