I have a Scenario where I have a java class written in JSP and its members are used in that JSP itself.
The JSP is part of a liferay portlet.
Now, I need to write that class for the velocity template in liferay theme so that I can access it in navigation.vm file.
Following is a dummy snippet -
xyz.jsp (part)
<body>
<%
final class DummyABC {
public String method1() {
}
public String method2() {
}
public String method3() {
}
}
%>
</body>
I need to access this class in my navigation.vm file.
Please help me through it.
You can write new java class and create a object in init.vm file so that navigation.vm file can access this variable
Related
Can anyone please guide me how to create a custom view in Xamarin.iOS using XCode.
Im trying to create a Custom Circular View with the class file. I was able to create a XIB file but not able to create a class file.
To continue on what you did, do the following.
Create an empty class and name it CircularView
public partial class CircularView : UIView
{
public static readonly NSString Key = new NSString("CircularView");
public static readonly UINib Nib;
static CircularView()
{
Nib = UINib.FromName("CircularView", NSBundle.MainBundle);
}
protected CircularView(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public static CircularView CreateView()
{
return (CircularView)Nib.Instantiate(null, null)[0];
}
}
Create another class and name it CircularView.designer.cs
[Register ("CircularView")]
partial class CircularView
{
void ReleaseDesignerOutlets ()
{
}
}
Edit project file and add DependUpon tags like below
BEFORE
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" />
AFTER
<Compile Include="Controls\CircularView.cs" />
<Compile Include="Controls\CircularView.designer.cs" >
<DependentUpon>CircularView.cs</DependentUpon>
</Compile>
this will ensure that VS shows the designer file as a child of CircularView.cs
where you want to use the new Custom view do the following
var v = CircularView.CreateView();
vwCustom.Add(v);
where vwCustom is a normal UIView added from Designer in my view controller, you can ofcourse name it anything.
Please let me know if you need further help.
I have a jsf jar library, and I want to load a specific JavaScript file (exist in the jar) in all pages of the JSF 2.2 project that use it, and without any additional configuration.
I want to load a specific JavaScript file exist in my library without use of
h:outputScript tag in the page( Neither the template nor the page )
Is this possible in jsf web application?
You can use UIViewRoot#addComponentResource() to programmatically add JSF resources. You can use a SystemEventListener on PostAddToViewEvent of <h:head> for this.
public class DynamicHeadResourceListener implements SystemEventListener {
#Override
public boolean isListenerForSource(Object source) {
return "javax.faces.Head".equals(((UIComponent) source).getRendererType());
}
#Override
public void processEvent(SystemEvent event) {
String library = "yourLibraryName";
String name = "yourScript.js"; // Can be dynamic here.
addHeadResource(FacesContext.getCurrentInstance(), library, name);
}
private void addHeadResource(FacesContext context, String library, String name) {
UIComponent resource = new UIOutput();
resource.getAttributes().put("library", library);
resource.getAttributes().put("name", name);
resource.setRendererType(context.getApplication().getResourceHandler().getRendererTypeForResourceName(name));
context.getViewRoot().addComponentResource(context, resource, "head");
}
}
In order to get it to run, register it in faces-config.xml of your module project as below:
<system-event-listener>
<system-event-listener-class>com.example.DynamicHeadResourceListener</system-event-listener-class>
<system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
<source-class>javax.faces.component.UIOutput</source-class>
</system-event-listener>
I have a web application that uses optional modules. The modules are implemented as Web Fragment projects, their jars may or may not be deployed with the war depending on the build profile.
A module can contain it's own module.taglib.xml with a http://company.com/module namespace and some tags.
The war xhtml templates use module tags like this:
<ui:composition ... xmlns:mod="http://company.com/module">
<c:if test="#{moduleDeployed}">
<mod:someTag />
</c:if>
Problems.
When the module is not deployed, the war pages work fine, but in ProjectStage.Development I get FacesMessage warnings:
Warning: This page calls for XML namespace
http://company.com/module declared with prefix mod but no
taglibrary exists for that namespace.
As far as I can see, JSF specification doesn't define what happens, when a template uses a nonexistent tag library. So with my current approach war pages can stop working after an upgrade or a switch to a different JSF implementation.
Questions.
Is there a (not very ugly) way to disable this specific warning?
Is there a better approach to using optional facelet tag libraries?
As of now I plan to disable the warning anyway I can: e.g. override Messages renderer and check message string if I have to. If the problem 2 manifests, make the build supply placeholder taglib.xml files for not deployed modules.
Even though placeholder taglibs seemed like a pretty good solution, they also seemed harder to implement and maintain.
So in the end I went with filtering the messages. This is likely Mojarra specific: the message text, the fact that the iterator allows removal (this isn't forbidden by the spec, but it's not required either). It's known to work with Mojarra 2.2.8 to 2.2.13.
public class SuppressNoTaglibraryExistsFacesMessage implements SystemEventListener {
private static final Pattern PTTRN_NO_TAGLIBRARY_EXISTS_FOR_NAMESPACE =
Pattern.compile("Warning: This page calls for XML namespace \\S+ declared with "
+ "prefix \\S+ but no taglibrary exists for that namespace.");
#Override
public void processEvent(SystemEvent event) {
Iterator<FacesMessage> messages = FacesContext.getCurrentInstance().getMessages();
while (messages.hasNext()) {
String messageSummary = messages.next().getSummary();
if (PTTRN_NO_TAGLIBRARY_EXISTS_FOR_NAMESPACE.matcher(messageSummary).matches()) {
messages.remove();
}
}
}
#Override
public boolean isListenerForSource(Object source) {
return true;
}
}
Bind the listener only in Development project stage.
public class SubscribeListenersAfterApplicationPostConstructListener
implements SystemEventListener {
#Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
Application application = (Application) event.getSource();
if (ProjectStage.Development.equals(application.getProjectStage())) {
application.subscribeToEvent(PostAddToViewEvent.class, UIViewRoot.class,
new SuppressNoTaglibraryExistsFacesMessage());
}
}
#Override
public boolean isListenerForSource(Object source) {
return source instanceof Application;
}
}
And in faces-config.xml:
<system-event-listener>
<system-event-listener-class><packages>.SubscribeListenersAfterApplicationPostConstructListener</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
</system-event-listener>
I have defined a configuration-action-class for loading the configuration of an existing portlet based on drools (liferay-portlet.xml):
<configuration-action-class>com.liferay.drools.action.ConfigurationActionImpl</configuration-action-class>
This class is processAction class:
public class ConfigurationActionImpl extends DefaultConfigurationAction {
#Override
public void processAction(
Now, I want to add another form with rows (inside the same config.jsp page). Exactly I want to call a different class from all of this rows (A call to SelectRules.java class):
<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
IRRule myRule = (IRRule)row.getObject();
String name = IRRule.class.getName();
String primKey = String.valueOf(myRule.getPrimaryKey());
%>
<liferay-ui:icon-menu>
<portlet:actionURL name="selectRule" var="selectURL">
<portlet:param name="resourcePrimKey" value="<%=primKey %>" />
</portlet:actionURL>
<liferay-ui:icon image="checked" message="SelectRule" url="<%=selectURL.toString() %>" />
</liferay-ui:icon-menu>
In my portlet.xml I defined the following portlet-class:
<portlet-class>com.myown.oriol.selectrules.portlet.SelectRules</portlet-class>
As you see, the main problem is that actionURL is looking to the configuration-action-class but what I exactly want is to call to the portlet-class(SelectRules.java) function called selectRules.
And the defined class selectRules that I want to call starts this way:
public class SelectRuleClass extends MVCPortlet {
public void selectRule(
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
Do you know what I need to solve this?? I don't know how I can merge this two classes with two different extensions considering that configurationActionImpl.java is already defined by another person.
In resume.. I need to call the function selectRule from configuration.jsp while selecting a Rule to be used. But the configuration-action-class is another one required for loading this existing portlet. And while selecting a rule I get this error...
86 does not have any paths specified
Thank you so much,
Oriol
Since the configuration.jsp is rendered by a liferay portlet with name 86 you would need to use <liferay-portlet:actionURL> instead of the simple <portlet:actionURL> since you would need to specify the portlet-name whose action method you need to call from configuration.jsp, something like this:
<liferay-ui:icon-menu>
<liferay-portlet:actionURL name="selectRule" var="selectURL" portletName="SelectRules_WAR_SelectRulesportlet">
<liferay-portlet:param name="resourcePrimKey" value="<%=primKey %>" />
</liferay-portlet:actionURL>
</liferay-ui:icon-menu>
If you have defined <portlet-name>SelectRules</portlet-name> than the attribute portletName of the tag would have value portletName="SelectRules_WAR_SelectRulesportlet", this is the portlet-id which is generated by liferay once you deploy the portlet.
This is liferay's convenient way to call one portlet (SelectRules) from another (86).
I've created a Sitefinity widget with only and iframe in it.
<%# Control Language="C#" AutoEventWireup="True" CodeBehind="ApplicationFrame.ascx.cs"
Inherits="MyProject.Web.Ui.Customized.EmbeddedApplications.ApplicationFrame" %>
<iframe runat="server" id="ApplicationIFrame" height="250" width="250" scrolling="no" frameborder="0" seamless="seamless" src=""></iframe>
In the Page_Load of the widget I trie to access any properties of the server side iframe but I always get "Object reference not set to an instance of an object".
Here's the C#
namespace MyProject.Web.Ui.Customized.EmbeddedApplications
{
[ControlDesigner(typeof(ApplicationFrameDesigner))]
public partial class ApplicationFrame : System.Web.UI.UserControl
{
public string FrameSourceUrl {get;set;}
public string FrameHeight { get; set; }
public string FrameWidth { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
//set the values of the iframe to the current properties
ApplicationIFrame.Attributes["src"] = FrameSourceUrl;
ApplicationIFrame.Attributes["height"] = FrameHeight;
ApplicationIFrame.Attributes["width"] = FrameWidth;
}
}
}
I recently change the project from a Website to a Web Application, but that hasn't seemed to impact the project in any way.
Other than that I can't see why this exception keeps being thrown no matter what I do.
Anyone else know what the problem might be?
Thanks,
Jacques
This may not work depending on the type of widget you have created. It would probably work for normal User controls, but not custom controls.
If you are following the sitefinity documentation, you can inherit from SimpleView. Then you have access to helper methods for retrieving controls from the template. So instead of this:
ApplicationIFrame.Attributes["src"] = FrameSourceUrl;
You can do this:
this.GetControl<HtmlControl>("ApplicationIFrame", true).Attributes["src"] = FrameSourceUrl;