다른 작업으로 모바일 버전이 필요한 작업을 작성하게되었습니다. 이를 달성하기 위해 모바일보기의 이름을 사용하여 주석을 달기 위해 사용한 런타임 주석을 @Mobile
작성했습니다. 모든 주석이 동작은 장치 검출을 수행 한 다음 MobileAction
로 구성된다 :
public class MobileAction extends Action<Mobile> {
public MobileAction() {
}
public MobileAction(Mobile configuration, Action<?> delegate) {
this.configuration = configuration;
this.delegate = delegate;
}
@Override
public Result call(Http.Context ctx) throws Throwable {
final Http.Request request = ctx.request();
final String userAgent = request.getHeader("User-Agent");
// See https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
if (userAgent.contains("Mobi")) {
ctx.args.put("viewName", configuration.value());
}
return delegate.call(ctx);
}
}
는 난 (임의로
@Mobile
의해 분사)를
viewName
인자를 검색하고 해당 뷰를 렌더링하기 위해 반사를 이용하는
DynamicRendered
클래스를 구현 하였다.
public class DynamicRenderer {
public static Html render(String viewName, Object... args) {
final Map<String, Object> ctxArgs = Http.Context.current().args;
final String view = ctxArgs.containsKey("viewName") ? ((String) ctxArgs.get("viewName")) : viewName;
// Get argument classes
final Class[] argClasses = new Class[args.length];
for (int i=0; i<args.length; i++) {
argClasses[i] = args[i].getClass();
}
try {
// Get view render method and invoke
final Class<?> clazz = Class.forName(view);
final Method render = clazz.getDeclaredMethod("render", argClasses);
final Html html = ((Html) render.invoke(null, args));
return html;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
다음, 대신 컨트롤러에 ok(viewName.render(...))
를 호출, 나는 ok(DynamicRenderer.render("viewName", ...))
감사를 부르지 만보기는 완전히 다른 것입니다. 따라서 CSS + JS 솔루션으로는 충분하지 않습니다. – monsieurBelbo
당신에게 달려 있습니다 ... FYI Foundation은 스크린 크기를 기반으로 UI의 특정 부분을 동적으로 숨기거나 표시 할 수있는 기능을 가지고 있습니다. 모든 것을 HTML로 렌더링 한 다음 필요한 것만 표시하려는 경우. 여분의 시간이 5 분이면 여기를보십시오. http://foundation.zurb.com/docs/components/visibility.html –
나는 이것을 투표했습니다. 오늘 데스크톱, 태블릿 및 모바일 화면에서 내보기가 괜찮아 보이게하는 동일한 작업을했습니다. 나는 부트 스트랩 3.3.6과 그것의 반응 유틸리티의 도움으로이 문제를 해결했다. 이 답변이 왜 누군가에 의해 다운 되었는 지 모르지만 실제로 Boostrap이 반응 형 툴링을 발전 시켰을 때 2014 년에는 조언이 좋았고 2014 년에는 더 나아졌습니다. –